const express = require('express');
const noteModel = require('../db/model/noteModel')
const ver = require('../middlewares/verifylogin');

let api = express.Router();
api.post('/addnote', (req, res) => {
    const { title, content } = req.body;
    noteModel.create({ title, content }, (err, data) => {
        res.render('jump.html', { name: '添加成功' })

    })
})
api.get('/delnote/:id', ver, (req, res) => {
    noteModel.deleteOne({ _id: req.params.id }, (err, data) => {
        if (err) {
            console.log(arr);
        } else {
            res.render('jump.html', { name: '删除成功' })
        }
    })
})
api.post('/update', (req, res) => {
    let { title, content, id } = req.body;
    noteModel.updateOne({ _id: id }, {
        title,
        content
    }, (err, data) => {
        // res.send('修改成功');
        res.render('jump.html', { name: "修改成功" });
    })
});
module.exports = api